package com.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jiyun.model.pojo.Coupon;
import com.jiyun.model.query.CouponQuery;
import com.jiyun.service.CouponService;
import com.jiyun.mapper.CouponMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【coupon】的数据库操作Service实现
* @createDate 2025-01-18 09:34:13
*/
@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon>
    implements CouponService{
    private final CouponMapper couponMapper;

    public CouponServiceImpl(CouponMapper couponMapper) {
        this.couponMapper = couponMapper;
    }

    @Override
    public IPage<Coupon> getPageList(CouponQuery query){
        //1.创建查询条件
        QueryWrapper<Coupon> qw = new QueryWrapper<>();
        //ToDo 查询条件

        //2.组件分页数据
        IPage<Coupon> page = new Page<>(query.getCurrentPage(), query.getPageSize());
        //3.查询
        baseMapper.selectPage(page,qw);
        //4.返回
        return page;
    }

    @Override
    public List<Coupon> getCoupon(Long id, Integer status) {
        String statusStr = "";
        switch (status) {
            case 1:
                statusStr = "已过期";
                break;
            case 2:
                statusStr = "已使用";
                break;
            case 0:
                return couponMapper.getCoupons(id);
        }
        return couponMapper.getCoupon(id, statusStr);
    }
}




